const { testsModel } = require("../models/testsModels");

const { Schema, model } = require("mongoose");

//类型模块
const typesSchema = new Schema(
  {
    type: String
  },
  { versionKey: false }
);
// 配置数据模型
const typesModel = model("typesModel", typesSchema, "types");

// 获取不同考试的所有试卷类型
async function getTests(req, res, next) {
  let result = await typesModel.find();
  res.send(result);
}

// 一种类型下的所有试卷信息
async function getOneTests(req, res, next) {
  let typeId = req.body;
  // console.log(typeId);

  let result = await testsModel
    .find({ typeId })
    .populate("typeId")
    .populate("exercisesId");

  res.send(result);
}

//通过试卷的_id得到当前试卷
async function getOnTest(req, res, next) {
  //传入试卷的_id,例如:{_id:111111}
  let result = await testsModel
    .find(req.body)
   .populate("typeId")
   .populate("exercisesId");
  if(result.length>0){
    res.send({
      code:200,
      message:'得到当前试卷',
      result
    })
  }else{
    res.send({
      code:500,
      message:'试卷不存在'
    })
  }

}
module.exports = {
  getTests,
  getOneTests,
  getOnTest
};


